#include "HCNetSDK.h"
#include <highgui.h>
#include <cv.h>
#include <stdio.h>
#include <stdlib.h>
typedef unsigned int * LPDWORD;

long get_Jpeg_Capture(char* ip, char* user, char* pass)
{
    // 初始化
	NET_DVR_Init();
	//设置连接时间与重连时间
	NET_DVR_SetConnectTime(2000, 1);
	NET_DVR_SetReconnect(10000, true);
    // 注册设备
	LONG lUserID;
	NET_DVR_DEVICEINFO_V30 struDeviceInfo;
	lUserID = NET_DVR_Login_V30(ip, 8000, user, pass, &struDeviceInfo);
	if (lUserID < 0)
	{
		printf("Login error, %d\n", NET_DVR_GetLastError());
		NET_DVR_Cleanup();
	}
	if(!NET_DVR_SetCapturePictureMode(BMP_MODE))
	{
		// cout<<"Set Capture Picture Mode error!"<<endl;
		// cout<<"The error code is "<<NET_DVR_GetLastError()<<endl;
	}
	return lUserID;
    // //定义JPEG图像质量
	// JpegPara = (NET_DVR_JPEGPARA *)malloc(sizeof(NET_DVR_JPEGPARA));
	// JpegPara->wPicQuality = 0;
	// JpegPara->wPicSize = 9;

    // char* Jpeg = (char*)malloc(200*1024);
	// DWORD len = 200*1024;
	// LPDWORD Ret = 0;
    
	// bool capture = NET_DVR_CaptureJPEGPicture_NEW(lUserID,1,JpegPara,Jpeg,len,Ret);
	// if(!capture)
	// {
	// 	printf("Error: NET_DVR_CaptureJPEGPicture_NEW = %d", NET_DVR_GetLastError());	
	// }
	// for(int i=0;i<200*1024;i++){
	// 	data[i] = Jpeg[i];
	// }
	// FILE *fp = fopen("567.jpg","wb");
    // fwrite(Jpeg, 1, 123 * 1024, fp);
    // fclose(fp);
}